(function (window, $, undefined) { var _block_namespaces_ = window._block_namespaces_ || (window._block_namespaces_ = {}); var name = "swiperPhotoImg77361_style1"; var swiperPhotoImg77361_style1 = _block_namespaces_[name] || (_block_namespaces_[name] = {}); $.extend(swiperPhotoImg77361_style1, { "init": init }) function init(nodeObj) { if (!!!nodeObj) { return; } var $selector = $('#' + nodeObj.pageNodeId); var nodeId = nodeObj.nodeId; if($selector.find('.lead_swiper_wrapper').length) { initSwiper($selector, nodeObj, nodeId) } else { initWatefall($selector, nodeObj) } leadComponentSite.globalMinimumUnitEvent.on(nodeObj.nodeId, function (notifyOriginType, selectedProdObj) { if (notifyOriginType && notifyOriginType == 'sku') { var relationImage = (selectedProdObj && selectedProdObj.relationImage) || ''; setSkuRelationImg($selector,relationImage) } }) videoFun($selector, nodeObj.encodeId, nodeObj); prodLabelPublic($selector, '.prodetail_labelfather'); // 放大镜 bigMaskFun($selector.get(0),nodeObj); //产品选型数据 try { var threeDData = JSON.parse(decode(nodeObj.templateSaveJson)) console.log("选型数据:",threeDData) threeDInit($selector, threeDData) } catch (err) { console.log("产品选型初始化失败") } } //base64解密 function decode(str) { // Going backwards: from bytestream, to percent-encoding, to original string. return decodeURIComponent(atob(str).split('').map(function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); } /** * 产品选型初始化 */ async function threeDInit($selector, threeDData) { /** * [产品选型模板] 3D模型展示模板 本地 "WEKpfUAMlLaZ" 线上 "WEKpfUAMlLaZ" * [产品选型模板] 3D模型展示(新)本地 "kmKUAfpwcaKo" 线上 "VGKpfUANUQWO" * [产品选型模板] 3D模型展示(嵌入) 本地 "hbKAfUpcHump" 线上 "hGpKfAUYSFbE" */ if (threeDData.basicSaveJson.templateObj.appName == "3D模型展示模板" || threeDData.basicSaveJson.templateObj.appId == "kmKUAfpwcaKo" || threeDData.basicSaveJson.templateObj.appId == "VGKpfUANUQWO" || threeDData.basicSaveJson.templateObj.appId == "hbKAfUpcHump" || threeDData.basicSaveJson.templateObj.appId == "hGpKfAUYSFbE" ) { //初始化按钮 var switch3DBtn = '
' $selector.find('.bigBox').append(switch3DBtn); if (!threeDData.templateSaveJson.resourceContent.newThree) { //3D模型展示模板 } else if (threeDData.templateSaveJson.resourceContent.newThree && threeDData.templateSaveJson.resourceContent.newThree == "1") { //3D模型展示(新) //获取国际化文本 var fit = $selector.find("#adaptationWindow").val() || "Fit model to window"; var up_y = $selector.find("#yUp").val() || "Set Y axis as up vector"; var up_z = $selector.find("#zUp").val() || "Set Z axis as up vector"; var flip = $selector.find("#flipUp").val() || 'Flip up vector'; var fix_up_on = $selector.find("#upwardFixation").val() || "Fixed up vector"; var fix_up_off = $selector.find("#freeOrbit").val() || "Free orbit"; var light_mode = $selector.find("#lightMode").val() || "Light mode"; var dark_mode = $selector.find("#darkMode").val() || "Dark mode"; var m_d = $selector.find("#modelDisplay").val() || "Model Display"; var b_c = $selector.find("#backgroundColor").val() || "Background Color"; var e_m = $selector.find("#environment").val() || "Environment"; var s_e = $selector.find("#showEdges").val() || "Show Edges"; var e_c = $selector.find("#edgeColor").val() || "Edge Color"; var r_d = $selector.find("#restorDefault").val() || "Reset to Default"; var u_b_i = $selector.find("#backgroundImage").val() || "Use as background image"; var m_l = $selector.find("#modelLoading").val() || "Loading Model"; var d_c = $selector.find("#defaultColor").val() || "Default Color"; var i_s = $selector.find("#importSettings").val() || "Import Settings"; var ourterHtml = ' ' $('body').append(ourterHtml); $selector.find('.bigBox .switch3D').unbind("click").bind("click", function () { if (!$(this).hasClass('.active-new')) { var modelSrc = threeDData.templateSaveJson.resourceContent.threeDUrl; var llist = { p_t: 1, l: { fit: fit, up_y: up_y, up_z: up_z, flip: flip, fix_up_on: fix_up_on, fix_up_off: fix_up_off, light_mode: light_mode, dark_mode: dark_mode, m_d: m_d, b_c: b_c, e_m: e_m, s_e: s_e, e_c: e_c, r_d: r_d, u_b_i: u_b_i, m_l: m_l, d_c: d_c, i_s: i_s } } var iframe_baseSrc = `https://a0.leadongcdn.cn/build/package/onlineviewer/index.html?params=${encodeURIComponent(JSON.stringify(llist))}/#model=` var tmp = ``; $('.new-threed-box .content').html(tmp); $('.new-threed-box').show(); $(this).addClass('active-new') } }) $(".new-threed-box .close").unbind("click").bind("click", function () { $('.new-threed-box .content').html(''); $('.new-threed-box').hide(); $selector.find('.bigBox .switch3D').removeClass('active-new'); }) $selector.find('.bigBox .switch3D').removeClass("hide") } else if (threeDData.templateSaveJson.resourceContent.newThree && threeDData.templateSaveJson.resourceContent.newThree == "2") { //3D模型展示(嵌入) var ourterHtml = ' ' $selector.find('.bigBox').append(ourterHtml); $selector.find('.bigBox .switch3D').unbind("click").bind("click", function () { if (!$(this).hasClass('.active-new')) { var modelSrc = threeDData.templateSaveJson.resourceContent.threeDUrl; $('.new-threed-iframe-box .content').html(modelSrc); $('.new-threed-iframe-box').show(); $(this).addClass('active-new') } }) $(".new-threed-iframe-box .close").unbind("click").bind("click", function () { $('.new-threed-iframe-box .content').html(''); $('.new-threed-iframe-box').hide(); $selector.find('.bigBox .switch3D').removeClass('active-new'); }) $selector.find('.bigBox .switch3D').removeClass("hide") } } } /** * 轮播 */ function initSwiper($selector, nodeObj, nodeId) { const $bigBoxContainer = $selector.find('.bigBox'); const renderCallback = function (options) { const upAndDown = { swiperSetting: function (config) { const swiper_config = { selector: config.selectorUuid + " .upAndDown .lead_swiper_thumbs", config: { spaceBetween: config.spaceBetween || 10, slidesPerView: config.slidesPerView || 5, freeMode: true, watchSlidesProgress: true } } if(config.autoplay && config.autoplay == '1') swiper_config.config.autoplay = { delay: config.autoplaySpeed, disableOnInteraction: false, } if(config.loop && config.loop == '1') swiper_config.config.loop = true return swiper_config }, thumbsSetting: function (swiper, config) { const swiper_config = { selector: config.selectorUuid + " .upAndDown .lead_swiper_wrapper", config: { navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", }, thumbs: { swiper: swiper, }, } } if(config.autoplay && config.autoplay == '1') swiper_config.config.autoplay = { delay: config.autoplaySpeed, disableOnInteraction: false, } if(config.loop && config.loop == '1') swiper_config.config.loop = true return swiper_config } } const leftAndRight = { swiperSetting: function (config) { const swiper_config = { selector: config.selectorUuid + " .leftAndRight .lead_swiper_thumbs", config: { spaceBetween: config.spaceBetween || 10, slidesPerView: config.slidesPerView || 5, direction: 'vertical', freeMode: true, watchSlidesProgress: true } } return swiper_config }, thumbsSetting: function (swiper, config) { // 需要计算外层容器高度 const slidesPerView = config.slidesPerView || 5 const spaceBetween = config.spaceBetween || 10 let totalHeight = 0; if($selector.find('.leftAndRight .lead_swiper_thumbs .swiper-slide').length > slidesPerView) { $selector.find('.leftAndRight .lead_swiper_thumbs .swiper-slide').slice(0, slidesPerView).each(function() { var height = $(this).outerHeight(); // 获取元素的高度,包括内边距和边框 totalHeight += height; // 累加高度 }); totalHeight += (slidesPerView - 1) * spaceBetween $selector.find('.leftAndRight .lead_swiper_thumbs').css('height', totalHeight + 'px') } const swiper_config = { selector: config.selectorUuid + " .leftAndRight .lead_swiper_wrapper", config: { navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", }, thumbs: { swiper: swiper, }, } } if(config.autoplay && config.autoplay == '1') swiper_config.config.autoplay = { delay: config.autoplaySpeed, disableOnInteraction: false, } if(config.loop && config.loop == '1') swiper_config.config.loop = true return swiper_config } } const leadSwiperOption = { upAndDown, leftAndRight } const initLeaSwiper = (setting, config) => { const { swiperSetting, thumbsSetting } = setting const swiperOption = swiperSetting(config) var swiper; if (document.querySelector(swiperOption.selector)) { swiper = new Swiper(swiperOption.selector, swiperOption.config); } const thembsOption = thumbsSetting(swiper, config) var swiper2 = new Swiper(thembsOption.selector, thembsOption.config); swiper2.on('slideChange', function () { $bigBoxContainer.attr("data-activeIndex", this.activeIndex); skuRelationImgEffect($selector); }); } initLeaSwiper(leadSwiperOption[options.currentVariable], options); // 获取当前的显示的产品图片 var nodeExtendParams = _block_namespaces_[nodeId] || (_block_namespaces_[nodeId] = {}); $.extend(nodeExtendParams, { getCurrentProductImg: function getSkuParams() { var prodDetailContainer = $selector.parents('.dynamic-component-container'); var photoImgEl = prodDetailContainer.find(".lead_swiper_wrapper .swiper-slide-active img"); if (photoImgEl.length > 0) { var prodPhotoUrl = photoImgEl.attr("src"); return prodPhotoUrl; } } }) } const componentParams = { callback: function () { console.log('swiperPhotoImg77361_style1 init callback') renderCallback(nodeObj) } } const params = Object.assign(nodeObj, componentParams) leadComponentSite.miniUnitProductImg.init(params); } function skuRelationImgEffect($selector){ var allPhotoImg = $selector.find('.lead_swiper_wrapper').find('.swiper-slide img'); allPhotoImg.each(function(index,item){ var _src = $(item).attr("src"); var _orginSrc = $(item).attr("data-original"); if(_src != _orginSrc){ $(item).attr("src",_orginSrc); } }) } // 设置sku关联图片 function setSkuRelationImg($selector,relationImage){ if(!relationImage){ skuRelationImgEffect($selector); return; } var activePhoto = $selector.find('.lead_swiper_wrapper').find('.swiper-slide-active img'); activePhoto.attr("src",relationImage); } /** * 瀑布流 */ async function initWatefall($selector, nodeObj) { await leadComponentSite.imagesloadedSourceImport.init({}); await leadComponentSite.masonrySourceImport.init({}); console.log('swiperPhotoImg77361_style1 masonrySourceImport init callback') const thatGroup = $selector.find('.lead_waterfall .lead_prodimg_container')[0] thatGroup.querySelectorAll('img[loading="lazy"]').forEach(img => { img.loading = 'eager'; // 改变为 'eager' 以立即加载 }); imagesLoaded(thatGroup, function() { var $grid = $(thatGroup).isotope({ itemSelector: '.swiper-slide', percentPosition: true, masonry: { columnWidth: '.swiper-slide', gutter: nodeObj.waterfallRowSpace || 20, } }); $grid.isotope('layout') }) const slidesPerView = nodeObj.slidesPerView || 5 const spaceBetween = nodeObj.spaceBetween || 10 let totalHeight = 0; if($selector.find('.leftAndRight .lead_swiper_thumbs .swiper-slide').length > slidesPerView) { $selector.find('.leftAndRight .lead_swiper_thumbs .swiper-slide').slice(0, slidesPerView).each(function() { var height = $(this).outerHeight(); // 获取元素的高度,包括内边距和边框 totalHeight += height; // 累加高度 }); totalHeight += (slidesPerView - 1) * spaceBetween $selector.find('.leftAndRight .lead_swiper_thumbs').css('height', totalHeight + 'px') } const initLeaSwiper = (config) => { const swiperSetting = { selector: config.selectorUuid + " .leftAndRight .lead_swiper_thumbs", config: { spaceBetween: config.spaceBetween || 10, slidesPerView: config.slidesPerView || 5, freeMode: true, direction: 'vertical', watchSlidesProgress: true, navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", } } } var swiper2 = new Swiper(swiperSetting.selector, swiperSetting.config); swiper2.on('slideChange', function () { $bigBoxContainer.attr("data-activeIndex", this.activeIndex); skuRelationImgEffect($selector); }); } const componentParams = { callback: function () { console.log('swiperPhotoImg77361_style1 init callback') initLeaSwiper(nodeObj); } } const params = Object.assign(nodeObj, componentParams) leadComponentSite.miniUnitProductImg.init(params); } function videoFun($selector, encodeId, nodeObj) { var photoBox = $selector.find(".bigBox"); // 播放按钮 const videoBtn = $selector.find(".playVideo") // 内链标签 const innerLinkEl = $selector.find(".innerLink") // 内链播放 const innerPlayEl = innerLinkEl.find("video") // 外链标签 const waiLinkEl = $selector.find(".waiLink") // 内链播放 const waiLinkPlayEl = waiLinkEl.find("iframe") // 播放方式 const thumbsVideoPlayWay = nodeObj.thumbsVideoPlayWay // 默认容器 var videoContainer = { container: innerLinkEl, playEl: innerPlayEl } // 关闭按钮 const closeVideoPlay = $selector.find(".closeVideoPayl") const video_container_box = $selector.find(".video_container_box") var url = '/phoenix/admin/video/purl'; /** * 检测图片是否有效(能打开) */ function checkImgExists(imgurl) { return new Promise(function(resolve, reject) { var ImgObj = new Image() ImgObj.src = imgurl ImgObj.onload = function(res) { resolve(res) } ImgObj.onerror = function(err) { reject(err) } }) } /** * 获取内链mp4缩略图 */ function getvideoMp4Thumbs(mp4Link) { return mp4Link + "?vframe/jpg/offset/1" } function getInnerThumb(urlLink) { if(!urlLink) return; const _urlLink = urlLink.toLocaleLowerCase(); if (_urlLink.indexOf('.mp4') != -1) { return getvideoMp4Thumbs(urlLink) } } /** * 获取youtube缩略图 */ function getvideoYoutobeThumbs(mp4Link) { const matchList = mp4Link.match(/live\/(.*)\?/); if(matchList && matchList[1]){ return `//i.ytimg.com/vi/${matchList[1]}/maxresdefault.jpg` } const matchList2 = mp4Link.match(/watch.*=(.*)/) if(matchList2 && matchList2[1]){ return `//i.ytimg.com/vi/${matchList2[1]}/maxresdefault.jpg` } } function getWaiThumb(urlLink){ if(!urlLink) return; const isYoutube = urlLink.indexOf('youtube') != -1; if(isYoutube){ return getvideoYoutobeThumbs(urlLink); } } /** * 设置视频缩略图 */ function setThumbFun(thumbImg) { if (!thumbImg) return; console.log('视频的缩略图链接',thumbImg); checkImgExists(thumbImg).then(()=>{ const $thumbEl = $selector.find(".video-cover-image"); $thumbEl.attr("src",thumbImg); }).catch(()=>{ //fail callback console.log('无效链接或者当前网络无法打开',thumbImg) }) } $.ajax({ url: url, type: 'get', data: { "pid": encodeId }, success: function (xhr) { try { // 缩略图 let thumbImg = ''; const srcVideoObj = JSON.parse(xhr); if (srcVideoObj) { if (srcVideoObj.mp4Url) { videoContainer.container = innerLinkEl; videoContainer.playEl = innerPlayEl; innerPlayEl.attr('data-src', srcVideoObj.mp4Url); thumbImg = getInnerThumb(srcVideoObj.mp4Url); } else if (srcVideoObj.vedioUrl) { // 是否外链 var isWaiLink = srcVideoObj.thirdLink && srcVideoObj.thirdLink === "1"; if (isWaiLink) { videoContainer.container = waiLinkEl; videoContainer.playEl = waiLinkPlayEl; waiLinkPlayEl.attr('data-src', srcVideoObj.vedioUrl); thumbImg = getWaiThumb(srcVideoObj.vedioUrl); } else { videoContainer.container = innerLinkEl; videoContainer.playEl = innerPlayEl; innerPlayEl.attr('data-src', srcVideoObj.vedioUrl); thumbImg = getInnerThumb(srcVideoObj.vedioUrl); } } setThumbFun(thumbImg); } } catch (e) { console.log(e); } } }); // 开启视频播放 videoBtn.unbind("click").bind("click", function () { if(thumbsVideoPlayWay == 'iframe') { video_container_box.removeClass('hide'); closeVideoPlay.removeClass('hide'); videoBtn.removeClass('active'); $(this).addClass('active'); var orginSrc = videoContainer.playEl.attr('data-src'); if (orginSrc && !videoContainer.playEl.attr('src')) { videoContainer.playEl.attr('src', orginSrc); } videoContainer.container.removeClass('hide'); photoBox.addClass('playVideoMode'); if (swiperPhotoImg77361_style1['closeBigMask_' + nodeObj.nodeId]) { swiperPhotoImg77361_style1['closeBigMask_' + nodeObj.nodeId](); } } else { var html = `